package com.gcsoftware.utils;

import java.io.*;

/**
 * Created by qs on 2018/3/27.
 */
public class ReadFileUtils {

    public static String getAbsolutePath(String absolutePath) {
        File file = new File("");
        String path = file.getAbsolutePath();
        return path + "/" + absolutePath;
    }

    public static String readFile(String filePath){
        File file = new File(filePath);
        InputStream input = null;
        try {
            input = new FileInputStream(file);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        StringBuffer buffer = new StringBuffer();
        byte[] bytes = new byte[1024];
        try {
            for(int n ; (n = input.read(bytes))!=-1 ; ){
                buffer.append(new String(bytes,0,n,"UTF-8"));
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        return buffer.toString();
    }
    public static String getBody(String val) {
        String start = "<body>";
        String end = "</body>";
        int s = val.indexOf(start) + start.length();
        int e = val.indexOf(end);
        return val.substring(s, e);
    }
}
